home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Arena Homepage
/
Amiga Arena Homepage CD Rom Edition.iso
/
Programme
/
Demoversionen
/
Anwender
/
ImEngV3.41p2
/
Extra
/
MainActor
/
IE_BatchProcess.ma
next >
Wrap
Text File
|
1996-10-14
|
13KB
|
430 lines
/*
** $VER: IE_BatchProcess.ma 1.1 (14/10 Stockholm/Sweden)
** Copyright © 1996 by Patrik M Nydensten
**
** Process all selected frames in MainActor's source project.
** Developed to work with MainActor 1.55 (Shareware/Aminet).
** May work with older/newer versions if arexx commands are the same.
** Uses IE Batch scripts. Requires Image Engineer 3.1 or higher.
*/
CFG_BATCH_DIR = '"IE:Arexx/Batch/"'
CFG_START_DIR = '"IE:"'
CFG_IE_PRIORITY = '-3'
options results
signal on error
signal on syntax
lf='0a'x ; dq='22'x ; sq='27'x
old_ie_pri = '0'
if ~show('P','MAINACTOR') then exit
address 'MAINACTOR'
'PrintAndStoreTxt' " "
'PrintAndStoreTxt' " »> IE BatchProcess v1.0 by Patrik M Nydensten <«"
if ~show(ports,'IMAGEENGINEER') then do
'PrintTxt' "Unable to locate IE's arexx port!"
exit
end
/* Get info from MainActor */
'GetSPName'
if RC ~= 0 then do
'PrintTxt' "No project loaded!"
exit
end
'GetSPSaver'
parse var result ma_savertype ma_savername .
'SetSPSaver' 'PIC' 'IFF'
'GetSPInfo'
parse var result width height colors pics caching loop cpf .
'ScreenToFront'
'RequestInteger' pics 'Enter total number of selected frames.'
num_files = result
'RequestSaveFile' "Select name for output dir."
if RC ~= 0 then do
'PrintTxt' "Aborted ..."
exit
end
dst_path = strip(result,'B','"')
if pos(':',dst_path) = 0 then do
'PrintAndStoreTxt' "Bad directory path! You can not use a relative path."
'PrintTxt' "Please select a volume before entering output dir path and name."
exit
end
if exists(dst_path) then do
'PrintTxt' "Directory with that name already exists!"
exit
end
address 'COMMAND' 'makedir' dst_path
/* Get batch script and check it -------------------------------------- */
'RequestFile' "Select IE Batch script."
if RC ~= 0 then do
'PrintTxt' "Aborted ..."
exit
end
bscript = strip(result,'B','"')
if ~exists(bscript) then do
'PrintTxt' "Unable to find IE batch script!"
exit
end
else do
binfo = bei('INFO') /* get extra info from batch */
if word(binfo,1) ~= 'OK' then do
'PrintTxt' "Error while accessing IE batch script!"
exit
end
end
address 'IMAGEENGINEER'
'IE_TO_FRONT'
nil = info_add_setup(binfo) /* setup optional extra info for batch */
/* Get config(s) from batch script ------------------------------------ */
'REQUEST' '"Select settings for first image."' '"Continue"'
bopt_f = bei('CONFIG')
'REQUEST' '"Select new settings for last image?"' '"Yes, new|No, use same"'
if (RESULT = 0) then bopt_l = bopt_f
else do
'REQUEST' '"Select settings for last image."' '"Continue"'
bopt_l = bei('CONFIG' sq'"'bopt_f'"'sq)
'REQUEST' '"Select settings calculation mode."' '"Linear|Faster|Slower|Spline"'
calc_type = RESULT
if calc_type ~= 1 then nil = add_mathlib()
end
if (bopt_f = '<ERROR>')|(bopt_l = '<ERROR>') then do
address 'MAINACTOR'
'PrintTxt' "Error while retrieving settings from batch script!"
exit
end
'REQUEST' '"Should I render the images?'lf||,
'Original sequence:' colors 'colors"' '"Yes, render|No, 24bit"'
render_do = result
if render_do = 1 then do
'RENDER_GET' '"Select render options."' '0 135168 8 256 1 0'
render_opts = result
if word(render_opts,5) = 0 then do
'GET_FILE' '"Select render palette to lock."' '"Lock"' '"IE:Palettes/"'
qpalette = result
end
'REQUEST' '"Show rendering in foreground?"' '"Yes, show me|No, hide it"'
render_show = result
end
/* Setup info & save out frames --------------------------------------- */
'PRIORITY_SET' CFG_IE_PRIORITY
old_ie_pri = result
address 'MAINACTOR'
'ScreenToFront'
'Save' dst_path||'/Image'
do i = 1 to 100000
if ~exists(dst_path||'/Image.'||right(i,5,'0')) then leave
end
if (num_files ~= i-1) then 'PrintAndStoreTxt' 'Warning: Number of saved images does not match user specified number.'
num_files = (i - 1)
if num_files < 1 then exit
'PrintAndStoreTxt' "Image processing started ..." time()',' date()
/* Start processing --------------------------------------------------- */
do i = 1 to num_files /* Process loop */
image_file = dst_path||'/Image.'||right(i,5,'0')
'PrintTxt' "Processing image" i 'of' num_files'.'
bei_proc = 'PROCESS' sq'"'image_file'"'sq sq'"'image_file'"'sq sq'"'calc_bopt(i)'"'sq get_info_add()
RESULT = bei(bei_proc)
if RESULT = '<ERROR>' then do
'ScreenToFront'
'PrintAndStoreTxt' "Batch script returned error while processing image" i '!'
'PrintTxt' ' ('image_file') ... Exiting ...'
exit
end
end /* end of process loop */
address 'MAINACTOR'
'ScreenToFront'
'PrintAndStoreTxt' "Image processing finished ..." time()',' date()
address 'IMAGEENGINEER'
'PRIORITY_SET' old_ie_pri
if render_do = 1 then do
address 'MAINACTOR' 'PrintAndStoreTxt' "Image rendering started ..." time()',' date()
do i = 1 to num_files /* Process loop */
image_file = dst_path||'/Image.'||right(i,5,'0')
address 'MAINACTOR' 'ScreenToFront'
address 'MAINACTOR' 'PrintTxt' "Rendering image" i 'of' num_files'.'
'OPEN' '"'image_file'"' '24'
project = result
if word(render_opts,5) = 0 then 'PALETTE_LOAD' project '"'qpalette'"'
'RENDER_SET' project render_opts
if render_show then 'RENDER' project render_opts
else 'RENDER' project render_opts 'QUIET'
'SAVE' project '"'image_file'"' '"ILBM CmpByteRun1"'
'CLOSE' project
end /* end of process loop */
address 'MAINACTOR' 'PrintAndStoreTxt' "Image rendering finished ..." time()',' date()
end /* do render */
/* Let MainActor act on created images */
address 'MAINACTOR'
if caching = "CACHING=YES" then 'OpenNewProject' "CACHING"
else 'OpenNewProject'
'SetSPLoader' 'PIC' 'Universal'
firstpic = dst_path || '/Image.00001'
lastpic = dst_path || '/Image.' || right(num_files,5,'0')
LoadProject firstpic lastpic
SetSPSaver ma_savertype ma_savername
'PrintAndStoreTxt' 'done ...'
exit
/* Procedures ------------------------------------------------------*/
BEI: /* Batch script caller */
parse arg bei_input
interpret 'CALL' '"'bscript'"' bei_input
bei_output = RESULT
address 'MAINACTOR'
return bei_output
/* Config settings twiner ---------------------------------------- */
Calc_bopt:
parse arg cur_filenum
calc_output = ''
bopt_fx = bopt_f ; bopt_lx = bopt_l
if (bopt_fx = bopt_lx) then calc_output = bopt_fx
else do forever
parse var bopt_fx val_fx bopt_fx
parse var bopt_lx val_lx bopt_lx
val_fx = strip(val_fx) ; val_lx = strip(val_lx)
if ((val_fx='')|(val_lx='')) then leave
if ((left(val_fx,1)='#')|(left(val_lx,1)='#')) then calc_output = calc_output val_fx
else do /* do linear/spline calculation */
select
when calc_type = 1 then calc_output = calc_output trunc( (val_fx+(val_lx - val_fx)*(cur_filenum-1)/(num_files-1)) )
when calc_type = 2 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*( (exp((-1)+5*(cur_filenum-1)/(num_files-1))-exp(-1)) /exp(4))/0.993262053 )
when calc_type = 3 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*(1-( exp(4-5*(cur_filenum-1)/(num_files-1)) /exp(4)))*1.006783655 )
when calc_type = 0 then calc_output = calc_output trunc( val_lx-(((cos(3.14159265*(cur_filenum-1)/(num_files-1))+1)/2)*(val_lx-val_fx)) )
otherwise nop
end /* select */
end /* do calc */
end
return strip(calc_output)
add_mathlib:
if ~show(L,'rexxmathlib.library') then do
if exists('LIBS:rexxmathlib.library') then do
if ~addlib('rexxmathlib.library',0,-30,0) then do
'PrintTxt' "Failed to load libs:rexxmathlib.library!"
end
end /* lib found on disk */
else do
'PrintTxt' "Failed to find libs:rexxmathlib.library!"
end
end /* lib exists in mem */
return 'OK'
/* Output optional extra info if necessary ---------------------------- */
get_info_add:
info_output = ''
if pos('S',add_input)~=0 then do
if sec_force = 1 then info_output = sq'"'strip(sec_filelist,B,'"')'"'sq
else do
parse var sec_filelist file ';' sec_filelist
info_output = sq'"'strip(file,B,'"')'"'sq
end
end
if pos('A',add_input)~=0 then do
if alp_force = 1 then info_output = info_output sq'"'strip(alp_filelist,B,'"')'"'sq
else do
parse var alp_filelist file ';' alp_filelist
info_output = info_output sq'"'strip(file,B,'"')'"'sq
end
end
if pos('F',add_input)~=0 then do
info_output = info_output sq'"'i':'num_files'"'sq
end
return strip(info_output)
/* Retrieve Secondary/Alpha image(s) --------------------------------- */
info_add_setup:
parse arg add_input
if pos('S',add_input)~=0 then do
if substr(add_input,pos('S',add_input)+1,1) = '1' then sec_files = 1
else sec_files = num_files
if sec_files > 1 then do /* select multifile */
'REQUEST' '"This Batch script requires that you select'lf ||,
num_files 'SECONDARY images."' '"Continue|Force single"'
if (RESULT = 0) then do
sec_files = 1 ; sec_force = 1
end
end
else do /* select single file */
'REQUEST' '"This Batch script requires that you select'lf ||,
'one SECONDARY image."' '" Continue "'
end
if sec_files = 1 then 'GET_FILE' '"Select one SECONDARY image."' '" OK "' CFG_START_DIR
else 'GET_FILES' '"Select' num_files 'SECONDARY image(s)."' '" OK "' CFG_START_DIR
if (RC=5) then exit
sec_filelist = RESULT
if sec_filelist = '' then exit
parse var sec_filelist file_1 ';' file_2 ';' nil
if (file_2~='')&(nil='')&(sec_files~=1) then do /* Ask for index range selection */
result = check_index_range(file_1,file_2)
parse var result '"'sec_filelist'"' '"'sec_files'"'
end /* Really index files? */
end /* end of get SEC */
if pos('A',add_input)~=0 then do
if substr(add_input,pos('A',add_input)+1,1) = '1' then alp_files = 1
else alp_files = num_files
if alp_files > 1 then do /* select multifile */
'REQUEST' '"This Batch script requires that you select'lf ||,
num_files 'ALPHA images."' '"Continue|Force single"'
if (RESULT = 0) then do
alp_files = 1 ; alp_force = 1
end
end
else do /* select single file */
'REQUEST' '"This Batch script requires that you select'lf ||,
'one ALPHA image."' '" Continue "'
end
if alp_files = 1 then 'GET_FILE' '"Select one ALPHA image."' '" OK "' CFG_START_DIR
else 'GET_FILES' '"Select' num_files 'ALPHA image(s)."' '" OK "' CFG_START_DIR
if (RC=5) then exit
alp_filelist = RESULT
if alp_filelist = '' then exit
parse var alp_filelist file_1 ';' file_2 ';' nil
if (file_2~='')&(nil='')&(alp_files~=1) then do /* Ask for index range selection */
result = check_index_range(file_1,file_2)
parse var result '"'alp_filelist'"' '"'alp_files'"'
end /* Really index files? */
end /* end of get ALP */
return 'OK'
Check_index_range:
parse arg file_1, file_2
range_list = file_1';'file_2
num_range = 2
basename = substr(file_1,1,lastpos('.',file_1))
basename_2 = substr(file_2,1,lastpos('.',file_2))
index_1 = substr(file_1,lastpos('.',file_1)+1) ; zlen = length(index_1)
index_2 = substr(file_2,lastpos('.',file_2)+1)
if (basename=basename_2)&(datatype(index_1,'N'))&(datatype(index_2,'N')) then do
'REQUEST' '"You have selected two images, both with the same basename'lf||,
'and both with an index number. Would you like to include all'lf||,
'images within the index range? ('index_2-index_1+1' images)"' '"Yes, index range|No, two images"'
if (Result = 1) then do
range_list = '' ; index_fix = 0
do i = strip(index_1,L,'0') to strip(index_2,L,'0')
if ~exists(basename || right(i,zlen,'0')) then do
if skip_all ~= 1 then do
'REQUEST' '"Could not locate file:'lf ||basename||right(i,zlen,'0')'"' '"Skip image|Skip all|Abort action"'
if Result ~= 0 then index_fix = index_fix + 1
if Result = 2 then skip_all = 1
if Result = 0 then exit
end
else index_fix = index_fix + 1
end
else range_list = range_list || basename || right(i,zlen,'0')||';'
end
num_range = index_2 - index_1 + 1 - index_fix
if (index_fix>0) then 'REQUEST' '"Skipped' index_fix 'images.' num_range 'images found."' '"Continue"'
if num_range < 2 then exit
end /* Do index range? */
end /* Is really index files? */
return '"'range_list'"' '"'num_range'"'
/*******************************************************************/
/* This is where control goes when an error code is returned by IE */
/* It puts up a message saying what happened and on which line */
/*******************************************************************/
syntax:
address 'IMAGEENGINEER'
'PRIORITY_SET' old_ie_pri
LAST_ERROR
IE_ERR = result
address 'MAINACTOR'
'ScreenToFront'
'PrintTxt' 'Error: Script failed ('RC') on line' SIGL '!'
if IE_ERR ~=RESULT then 'IE error message:' IE_ERR
exit
end
error:
address 'IMAGEENGINEER'
'PRIORITY_SET' old_ie_pri
LAST_ERROR
IE_ERR = result
address 'MAINACTOR'
'ScreenToFront'
'PrintTxt' 'Error: Script failed on line' SIGL
if IE_ERR ~=RESULT then 'IE error message:' IE_ERR
exit
end